//
//  UIBarButtonItem+Button.m
//  BaiSi
//
//  Created by UJY on 2016/12/5.
//  Copyright © 2016年 谭占武. All rights reserved.
//

#import "UIBarButtonItem+Button.h"

@implementation UIBarButtonItem (Button)



+(instancetype)barItemWithName:(NSString *)name HightName:(NSString *)highName target:(id)target action:(SEL)action{
    UIButton *button1 = [[UIButton alloc]init];
    [button1 setImage:[UIImage imageNamed:name] forState:UIControlStateNormal];
    [button1 setImage:[UIImage imageNamed:highName] forState:UIControlStateHighlighted];
    [button1 sizeToFit];
    [button1 addTarget:target action:action forControlEvents:UIControlEventTouchUpInside];
    //通过view包装以解决超出范围响应bug
    UIView *view = [[UIView alloc]initWithFrame:button1.frame];
    [view addSubview:button1];
    return [[self alloc]initWithCustomView:view];
}

+(instancetype)barItemWithName:(NSString *)name selectedName:(NSString *)selectedName target:(id)target action:(SEL)action{
    UIButton *button1 = [[UIButton alloc]init];
    [button1 setImage:[UIImage imageNamed:name] forState:UIControlStateNormal];
    [button1 setImage:[UIImage imageNamed:selectedName] forState:UIControlStateSelected];
    [button1 sizeToFit];
    [button1 addTarget:target action:action forControlEvents:UIControlEventTouchUpInside];
    //通过view包装以解决超出范围响应bug
    UIView *view = [[UIView alloc]initWithFrame:button1.frame];
    [view addSubview:button1];
    return [[self alloc]initWithCustomView:view];
}

@end
